package com.zjitc.controller.manage;/**
 * Create by IntelliJ IDEA
 *
 * @author: MaoYongQi
 * @date-Time: 2018/4/3 11:02
 * @description:
 */

import com.zjitc.common.ServerResponse;
import com.zjitc.dao.ProductDao;
import com.zjitc.model.Product;
import com.zjitc.service.ProductService;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.HttpSessionRequiredException;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Create by IntelliJ IDEA
 *
 * @author: MaoYongQi
 * @date-Time: 2018/4/3 11:02
 * @description:
 */
@Controller
@RequestMapping("/manage/product")
public class ProductManageController {

  @Autowired
  private ProductService service;

  @RequestMapping("/list")
  @ResponseBody
  public ServerResponse<Product> List(
      @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
      @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
      HttpSession session
  ) {
    ServerResponse<Product> response = service.findAllByList(pageNum, pageSize, session);
    return response;
  }


  @RequestMapping("/search")
  @ResponseBody
  public ServerResponse<Product> search(
      @RequestParam(value = "productName", required = false ) String productName,
      @RequestParam(value = "productId", required = false) String productId,
      @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
      @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
      HttpSession session
  ) {
    ServerResponse<Product> response = service
        .serach(productName, productId, pageNum, pageSize, session);
    return response;
  }

  @RequestMapping("/set_sale_status")
  @ResponseBody
  public ServerResponse<Product> setStatus(Integer productId,Integer status){
    return service.setStatus(productId,status);
  }


  @RequestMapping("save")
  @ResponseBody
  public ServerResponse<Product> save(Product product){
    return service.update(product);
  }
}
